cat('Creating Table A27 \n\n')

dat = read.csv('TableA27_data.csv')
dat.uo = dat[dat$uo.non.uo == 'uo',]
dat.sec = dat[dat$uo.non.uo != 'uo',]

##formulas specific to task selection
use.formula = as.formula(paste('ingroup.task ~ ',master.formula,sep = ''))
use.formula.reduced = as.formula(paste('ingroup.task ~ ',master.formula.reduced,sep = ''))
use.formula.interactions = as.formula(paste('ingroup.task ~ ',master.formula.interactions,sep = ''))


##UO
##regressions
reg.uo.task = lm(use.formula, data = dat.uo)
clustered.se = cl(dat.uo, reg.uo.task, dat.uo$index.city)
reg.uo.task$se = clustered.se

reg.uo.task.reduced = lm(use.formula.reduced, data = dat.uo)
clustered.se = cl(dat.uo, reg.uo.task.reduced, dat.uo$index.city)
reg.uo.task.reduced$se = clustered.se

reg.uo.task.interactions = lm(use.formula.interactions, data = dat.uo)
clustered.se = cl(dat.uo, reg.uo.task.interactions, dat.uo$index.city)
reg.uo.task.interactions$se = clustered.se


##Secular
##regressions
reg.sec.task = lm(use.formula, data = dat.sec)
clustered.se = cl(dat.sec, reg.sec.task, dat.sec$index.city)
reg.sec.task$se = clustered.se

reg.sec.task.reduced = lm(use.formula.reduced, data = dat.sec)
clustered.se = cl(dat.sec, reg.sec.task.reduced, dat.sec$index.city)
reg.sec.task.reduced$se = clustered.se

reg.sec.task.interactions = lm(use.formula.interactions, data = dat.sec)
clustered.se = cl(dat.sec, reg.sec.task.interactions, dat.sec$index.city)
reg.sec.task.interactions$se = clustered.se

outtable = apsrtable(reg.uo.task.reduced,
                     reg.uo.task,
                     reg.uo.task.interactions,
                     reg.sec.task.reduced,
                     reg.sec.task,
                     reg.sec.task.interactions,
                     Sweave = T,
                     coef.names = coef.names,
                     stars = 'default',
                     model.names = c('UO','UO','UO','Non UO','Non UO','Non UO'),
                     notes = ''
)
writeLines(
  outtable, 'TableA27.tex')

